#include "AbstractTimerThread.h"
#include <ctime>
#include <math.h>
using namespace std;

AbstractTimerThread::AbstractTimerThread(unsigned long interval)
{
	m_interval = interval;
}

AbstractTimerThread::~AbstractTimerThread(void)
{
}

void AbstractTimerThread::DoAction()
{
	do
	{	
		clock_t start = clock();
		OnTime();
		clock_t end = clock();
		long elapse = ceil((double)((end - start) / CLOCKS_PER_SEC));
		if(elapse >= m_interval)
			continue;
		
		long time = m_interval - elapse;
		m_timeWaiter.SyncWait(time);
	} while(true);
}

void AbstractTimerThread::SetInterval(unsigned long interval)
{
	m_interval = interval;
}